package com.summer.algorithm;

import java.math.BigInteger;

public class Probability {
	
	public static long factorial(int n) {
		BigInteger f = new BigInteger("1");
		for(long i = 2; i <= n; i++) {
			f = f.multiply(new BigInteger(String.valueOf(i)));
		}
		return f.longValue();
	}
	
	public static double celc(int n, int k, double p) {
		
//		[n!/k!(n- k)!]p ^ k(n-k)^(n- k)
		
		int nk = n - k;
		long fn = factorial(n);
		long fk = factorial(k);
		long fnk = factorial(nk);
		
		System.out.println(String.format("fnk==== %s   %s   %s", fn, fk, fnk));
		
		double tmpC = fn / (fk * fnk);
		

		return tmpC * Math.pow(p, k) * Math.pow(1 - p, nk);
	}
	
	public static void main(String[] args) {
		System.out.println("结果====" + celc(10, 8, 0.2));
	}
}
